<!-- src/views/lawyer/LawyerInfoDetail.vue -->
<script setup>
import { ref, defineProps, defineEmits, watch } from 'vue'

const emit = defineEmits(['update:visible'])
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  lawyerData: {
    type: Object,
    default: () => ({})
  }
})

const dialogVisible = ref(false)

// 监听visible属性变化
watch(
    () => props.visible,
    (newVal) => {
      dialogVisible.value = newVal
    },
    { immediate: true }
)

// 监听dialogVisible变化并emit事件
watch(
    () => dialogVisible.value,
    (newVal) => {
      if (!newVal) {
        emit('update:visible', false)
      }
    }
)

const handleClose = () => {
  dialogVisible.value = false
}

// 格式化状态显示
const formatStatus = (status) => {
  const statusMap = {
    'AVAILABLE': '正常',
    'PAUSED': '暂停',
    'DELETED': '注销'
  }
  return statusMap[status] || status || '-'
}

// 格式化认证状态
const formatCertification = (isCertified) => {
  return isCertified === 1 ? '已认证' : '未认证'
}
</script>

<template>
  <el-dialog
      v-model="dialogVisible"
      title="律师详情"
      width="700px"
      @close="handleClose"
      class="lawyer-detail-dialog"
  >
    <div class="lawyer-detail-content">
      <el-card class="lawyer-card" shadow="never">
        <template #header>
          <div class="card-header">
            <span class="card-title">基础信息</span>
          </div>
        </template>
        <el-row :gutter="20">
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">律师ID:</span>
              <span class="info-value">{{ lawyerData.id || '-' }}</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">关联用户ID:</span>
              <span class="info-value">{{ lawyerData.userId || '-' }}</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">执业证号:</span>
              <span class="info-value">{{ lawyerData.licenseNo || '-' }}</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">专业领域:</span>
              <span class="info-value">{{ lawyerData.specialty || '-' }}</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">执业年限:</span>
              <span class="info-value">{{ lawyerData.yearsOfPractice || '-' }} 年</span>
            </div>
          </el-col>
        </el-row>
      </el-card>

      <el-card class="lawyer-card" shadow="never">
        <template #header>
          <div class="card-header">
            <span class="card-title">业务信息</span>
          </div>
        </template>
        <el-row :gutter="20">
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">案件成功率:</span>
              <span class="info-value">{{ lawyerData.successRate || '-' }}</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">服务区域:</span>
              <span class="info-value">{{ lawyerData.serviceArea || '-' }}</span>
            </div>
          </el-col>
          <el-col :span="24">
            <div class="info-item">
              <span class="info-label">个人介绍:</span>
              <span class="info-value info-value-text">{{ lawyerData.introduction || '-' }}</span>
            </div>
          </el-col>
        </el-row>
      </el-card>

      <el-card class="lawyer-card" shadow="never">
        <template #header>
          <div class="card-header">
            <span class="card-title">认证与状态</span>
          </div>
        </template>
        <el-row :gutter="20">
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">认证状态:</span>
              <span class="info-value" :class="{
                'certified': lawyerData.isCertified === 1,
                'uncertified': lawyerData.isCertified !== 1
              }">{{ formatCertification(lawyerData.isCertified) }}</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">认证时间:</span>
              <span class="info-value">{{ lawyerData.certificationTime || '-' }}</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">工作状态:</span>
              <span class="info-value" :class="{
                'status-available': lawyerData.status === 'AVAILABLE',
                'status-paused': lawyerData.status === 'PAUSED',
                'status-deleted': lawyerData.status === 'DELETED'
              }">{{ formatStatus(lawyerData.status) }}</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">服务评级:</span>
              <span class="info-value">{{ lawyerData.serviceRating || '-' }}</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">最近评级时间:</span>
              <span class="info-value">{{ lawyerData.lastRatingTime || '-' }}</span>
            </div>
          </el-col>
        </el-row>
      </el-card>

      <el-card class="lawyer-card" shadow="never">
        <template #header>
          <div class="card-header">
            <span class="card-title">案件统计</span>
          </div>
        </template>
        <el-row :gutter="20">
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">接案总量:</span>
              <span class="info-value">{{ lawyerData.casesTotal || '-' }}</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">结案量:</span>
              <span class="info-value">{{ lawyerData.casesClosed || '-' }}</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">平均响应时间:</span>
              <span class="info-value">{{ lawyerData.avgResponseHours || '-' }} 小时</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">胜诉案件数:</span>
              <span class="info-value">{{ lawyerData.casesWon || '-' }}</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="info-item">
              <span class="info-label">胜诉率:</span>
              <span class="info-value">{{ lawyerData.winRate || '-' }}</span>
            </div>
          </el-col>
        </el-row>
      </el-card>
    </div>

    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="handleClose" round>关闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style scoped>
.lawyer-detail-dialog {
  border-radius: 8px;
  overflow: hidden;
}

.lawyer-detail-content {
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 10px;
}

.lawyer-card {
  margin-bottom: 20px;
  border-radius: 8px;
  border: 1px solid #ebeef5;
}

.lawyer-card:last-child {
  margin-bottom: 0;
}

.card-header {
  display: flex;
  align-items: center;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
  position: relative;
  padding-left: 12px;
}

.card-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 16px;
  background-color: #409eff;
  border-radius: 2px;
}

.info-item {
  display: flex;
  margin-bottom: 15px;
  align-items: flex-start;
}

.info-item:last-child {
  margin-bottom: 0;
}

.info-label {
  width: 120px;
  color: #606266;
  font-weight: 500;
  flex-shrink: 0;
}

.info-value {
  flex: 1;
  color: #303133;
  word-break: break-all;
}

.info-value-text {
  line-height: 1.5;
}

.certified {
  color: #67c23a;
  font-weight: 500;
}

.uncertified {
  color: #909399;
}

.status-available {
  color: #67c23a;
  font-weight: 500;
}

.status-paused {
  color: #e6a23c;
  font-weight: 500;
}

.status-deleted {
  color: #f56c6c;
  font-weight: 500;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  padding: 20px 0 0;
}

:deep(.el-dialog__body) {
  padding: 20px;
}

:deep(.el-card__header) {
  padding: 12px 20px;
  background-color: #f5f7fa;
  border-bottom: 1px solid #ebeef5;
}

:deep(.el-card__body) {
  padding: 20px;
}
</style>
